﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EQual.MainModule.Reviews.DetailsViews
{
   public  class ReviewDecisionsPresenter : EQual.Infrastructure.MVPFramework.Presenters.ListPresenterDefault <DetailsViews.ReviewDecisionsView, object>
    {
        ReviewDecisiolnPresentationModel Model;
        public ReviewDecisionsPresenter()
        {
            View = new DetailsViews.ReviewDecisionsView();
            Model = new ReviewDecisiolnPresentationModel();

            Model.Presenter = this;

            View.ItemAdded += new EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<object>>(View_ItemAdded);
        }

        void View_ItemAdded(object sender, Microsoft.Practices.Composite.Events.DataEventArgs<object> e)
        {
            new DataAccesLayer.ReviewsDataAccesLayer().AddNewParticipantToReview (ActiveItem, e.Value);
        }

        public override void Dispaly(object item)
        {
            View.Model = new
            {
                ItemsCollection = GetCollection(item),
                ReviewSubjects = GetReviewSubjects(item)
            };

        }

        private object GetReviewSubjects(object item)
        {
            return new DataAccesLayer.ReviewsDataAccesLayer().GetReviewSubjects(item);
        }

        private object GetCollection(object item)
        {
            return new DataAccesLayer.ReviewsDataAccesLayer().GetDecisionsOfReview(item);
        }
    }



    public class ReviewDecisiolnPresentationModel : EQual.Infrastructure.MVPFramework.Models.PresentationModelBase<DataAccesLayer.ReviewsSubjectDecision>
    {
        public ReviewDecisionsPresenter Presenter { get; set; }

        public ReviewDecisiolnPresentationModel()
        {
 
        }

        protected override IEnumerable<DataAccesLayer.ReviewsSubjectDecision> GetCollection()
        {
            return new DataAccesLayer.ReviewsDataAccesLayer().GetDecisionsOfReview(Presenter .ActiveItem ) as IEnumerable <DataAccesLayer .ReviewsSubjectDecision >;
        }

        public System.Collections.IEnumerable ReviewSubjects
        {
            get { return GetReviewSubjects(); }
        }

        private System.Collections.IEnumerable GetReviewSubjects()
        {
            return new DataAccesLayer.ReviewsDataAccesLayer().GetReviewSubjects(Presenter .ActiveItem );
        }

    }

}
